<template>
	<web-view class="web-view" :webview-styles="webviewStyles" id="webview" :src="url" :style="{width: windowW + 'px', height: windowH + 'px'}" @message="onWebviewMessage"></web-view>
</template>

<script>
	export default {
		data() {
			return {
				windowH: 0,
				windowW: 0,
				webviewStyles: {
					progress: {
						color: 'transparent'
					}
				},
				url: ''
			}
		},
		onLoad(option) {
			this.url = decodeURIComponent(option.url);
			try {
				const res = uni.getSystemInfoSync();
				this.windowW = res.windowWidth;
				this.windowH = res.windowHeight;
			} catch (e) {
				// error
			}
		},
		methods: {
			onWebviewMessage(message) {
			    console.log('onWebviewMessage>>>>>', message)
			    const { detail: { type, token, url ,authFlowId} } = message
			    //授权认证流程才返回authFlowId
				if (type === 'AUTH_FINISH') {
					uni.navigateBack({
						delta: 1
					})
					return
				}
			    if (type === 'IDENTITY_ALI_FACE_AWAKE') {
			      my.startAPVerify({
			      url,
			      certifyId: token,
			      success: function (res) {
			        console.log('success', res)
					
			      },
			      fail: function (res) {
			        console.log('fail', res)
			      },
			      complete: function (res) {
			        console.log('complete', res)
			      }
			    })
			    return
			    }
			    if (type === 'WILL_DONE') {
			      console.log('WILL_DONE>>do something')
			
			      return
			    }
			    if (type === 'RN_DONE') {
			      console.log('RN_DONE>>do something')
			    
			      return
			    }
			    if (type === 'E_AUTH_FINISHED') {
			      console.log('RN_DONE>>do something')
			      console.log("authFlowId",authFlowId)
			      // 要跳转的页面或进行其他操作
			// my.navigateTo({
			//   url: '/pages/index/index',
			//   });
			      return
			    }
			}
		}
	}
</script>
